<?php
class post_like { 
    var $pl_id;
    var $pl_p_id;
    var $pl_u_id;
    var $pl_date;


    function Delete(){

        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();

        $q = " delete  from post_like where pl_id ='".$this->pl_id."' " ;
        $rs = $DB->EjecutarQuery($q);

        $DB->DesconectarBD();
        return $rs;
    }

    function Update(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        $query = " " ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;  
    }

    function GetData(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
         
        $query = " Select * from post_like where pl_id ='".$this->pl_id."' ";
        $rs = $DB->ObtenerData($query, "post_like" );

        $this->pl_id = $rs[0]["pl_id"];
        $this->pl_p_id = $rs[0]["pl_p_id"];
        $this->pl_u_id = $rs[0]["pl_u_id"];
        $this->pl_date = $rs[0]["pl_date"];

        $DB->DesconectarBD();        
    }

    function Save(){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        $query = " INSERT INTO post_like (
                     pl_id, pl_p_id, pl_u_id, pl_date)
                    VALUES (NULL, '$this->pl_p_id', '$this->pl_u_id', '$this->pl_date');" ;
        
        $rs = $DB->EjecutarQuery($query);        
        $DB->DesconectarBD();        
        return $rs;        
    }
    
    function GetList($vals = false, $orderby = false, $lim= false){
        include_once 'recursos/conexionMysql.php';
        $DB = new conexionMysql();
        $DB->ConectarBD();
        
        if ($_REQUEST["seccion"] == "postlike" ) { //modulo post_like
        
            if(!isset($_REQUEST["li"])){
                $li = 0;
            }else{
                $li = $_REQUEST["li"];
            }               

            if(isset($_REQUEST["page"])){
                $li = ($_REQUEST["page"]* $_SESSION['PREF']['LIST_LIMIT'])- $_SESSION['PREF']['LIST_LIMIT'];
            }

            if(!$vals){
                $vals = " * ";            
            }

            if(!$lim){
                $limit ="LIMIT ".$li.", ".$_SESSION['PREF']['LIST_LIMIT']." ";
            }

            if($orderby){            
                $order =" ORDER BY $orderby ";
            }else{
                $order =" ORDER BY pl_date desc,  asc ";
            }

            if(isset($_REQUEST["estado"]) && $_REQUEST["estado"] <> 99 ){ 
                $where .= " and  = ".$_REQUEST["estado"]."  ";
            }   

            if($_REQUEST["filtro"]){
                $query = " Select $vals from post_like where  like '%".$_REQUEST["filtro"]."%' $where
                                $order  $limit ";
            }else{
                $query = " Select $vals from post_like where 1=1 $where   $order  $limit   ";
            }
            
        } else {  //desde fuera del MODULO POST_LIKE
            
             $query = " Select $vals from post_like where  = 1 $where  ";
            
        }
        
        $rs = $DB->ObtenerData($query, "post_like");

        if (trim($vals) != "count(*)"){

            foreach ($rs as $key => $val) {
                $p = new post_like();
                $p->set_pl_id($val["pl_id"]);
                $p->set_pl_p_id($val["pl_p_id"]);
                $p->set_pl_u_id($val["pl_u_id"]);
                $p->set_pl_date($val["pl_date"]);
                $rs2[] = $p;
            }

            $rs = $rs2;

            include_once 'recursos/funciones.php';
            $e = getEstado();        
            if(is_array($rs)){
                foreach ($rs as $key => $value) {
                    if ($value[""] == 1) {
                        $rs[$key][""] = "<img src='images/png/estado_habilitado.png' />".$e[$value[""]];
                    } else {
                        $rs[$key][""] = "<img src='images/png/estado_deshabilitado.png' />".$e[$value[""]];
                    }  
                }
            }
        }
        $DB->DesconectarBD();      
        return $rs;                
    }

    function get_pl_id(){
        return $this->pl_id;
    }
    function set_pl_id($val){
        $this->pl_id = $val;
    }

    function get_pl_p_id(){
        return $this->pl_p_id;
    }
    function set_pl_p_id($val){
        $this->pl_p_id = $val;
    }

    function get_pl_u_id(){
        return $this->pl_u_id;
    }
    function set_pl_u_id($val){
        $this->pl_u_id = $val;
    }

    function get_pl_date(){
        return $this->pl_date;
    }
    function set_pl_date($val){
        $this->pl_date = $val;
    }

}